package br.ucb.janela;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import br.ucb.servicos.Servicos;


public class DiologFistConnect extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9086503171321987875L;
	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	private JPasswordField textField_1;

	/**
	 * Create the dialog.
	 */
	public DiologFistConnect() {
		setTitle("Conexão Com o Banco");
		setBounds(100, 100, 364, 241);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		setModal(true);
		textField = new JTextField();
		textField.setColumns(10);
		textField.setText("root");
		textField.selectAll();
		
		
		JLabel lblUsuario = new JLabel("Usuario:");
		
		JLabel lblSenha = new JLabel("Senha:");
		
		textField_1 = new JPasswordField();
		textField_1.setColumns(10);
		
		JLabel lblFalaNaConeco = new JLabel("Falha na Conexão Com o Banco de Dados");
		lblFalaNaConeco.setForeground(Color.RED);
		
		JLabel lblPorFavorInforme = new JLabel("Por Favor Informe o Usuário e Senha do Banco");
		
		JButton btnOk = new JButton("OK");
		btnOk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					Servicos.salvaSenhaBanco(textField.getText(),textField_1.getText());
					dispose();
					Servicos.verificaBancoAcesso();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(lblUsuario)
						.addComponent(lblSenha))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
						.addComponent(textField_1)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, 233, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(34, Short.MAX_VALUE))
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap(152, Short.MAX_VALUE)
					.addComponent(btnOk)
					.addGap(141))
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap(45, Short.MAX_VALUE)
					.addComponent(lblPorFavorInforme)
					.addGap(35))
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap(53, Short.MAX_VALUE)
					.addComponent(lblFalaNaConeco)
					.addGap(50))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblFalaNaConeco)
					.addGap(12)
					.addComponent(lblPorFavorInforme)
					.addGap(12)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblUsuario)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblSenha)
						.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
					.addComponent(btnOk)
					.addContainerGap())
		);
		contentPanel.setLayout(gl_contentPanel);
	}

	
	
}
